---
description: "Reference for Nitric's v0 JVM library - Gets a reference to a child collection on a document."
---

# JVM - collection.doc.collection()

Gets a reference to a child collection on a document.

<Tabs syncKey="jvm-lang">

<TabItem label="Java">

```java
import io.nitric.Nitric;
import io.nitric.resources.CollectionPermission;

class User {
  String name;
  int age;

  public User(String name, int age) {
    this.name = name;
    this.age = age;
  }
}

public class Application {
  public static void main(String[] args) {
    var profiles = Nitric.INSTANCE.collection("profiles", User.class).with(CollectionPermission.Read);

    var drakesProfile = profiles.doc("Drake Mallard");

    var drakesEnemies = drakesProfile.collection("enemies", User.class);

    Nitric.INSTANCE.run();
  }
}
```

</TabItem>

<TabItem label="Kotlin">

```kotlin
import io.nitric.Nitric
import io.nitric.resources.CollectionPermission

data class User(val name: String, val age: Int)

fun main() {
  val profiles = Nitric.collection<User>("profiles").with(CollectionPermission.Read)

  val drakesProfile = profiles.doc("Drake Mallard")

  val drakesEnemies = drakesProfile.collection<User>("enemies")

  Nitric.run()
}
```

</TabItem>

</Tabs>

## Parameters

<Properties>
  <Property name="name" required type="String">
    The name of the child collection to reference
  </Property>
  <Property name="type" required type="Class<T>">
    The type of documents that will be stored in the collection.
  </Property>
</Properties>

<Note>Document collection relationships can be at most 1 deep.</Note>

<Tabs syncKey="jvm-lang">

<TabItem label="Java">

```java
import io.nitric.Nitric;
import io.nitric.resources.CollectionPermission;

class User {
  String name;
  int age;

  public User(String name, int age) {
    this.name = name;
    this.age = age;
  }
}

public class Application {
  public static void main(String[] args) {
    var profiles = Nitric.INSTANCE.collection("profiles", User.class).with(CollectionPermission.Read);

    profiles
      .doc("Drake Mallard")
      .collection("enemies", User.class))
      .doc('Steel Beak') // ✔️ We can go this deep
      .collection('enemies', User.class) // ❌ But not this deep

    Nitric.INSTANCE.run();
  }
}
```

</TabItem>

<TabItem label="Kotlin">

```kotlin
import io.nitric.Nitric
import io.nitric.resources.CollectionPermission

data class User(val name: String, val age: Int)

fun main() {
  val profiles = Nitric.collection<User>("profiles").with(CollectionPermission.Read)

  profiles
    .doc("Drake Mallard")
    .collection<User>("enemies")
    .doc('Steel Beak') // ✔️ We can go this deep
    .collection<User>('enemies') // ❌ But not this deep

  Nitric.run()
}
```

</TabItem>

</Tabs>

### See also

- [collection()](./collection)
